<?php
/**
 * Created by PhpStorm.
 * User: Administrator
 * Date: 2018/11/30/0030
 * Time: 9:40
 */

namespace app\sports_admin\controller;

use app\sports_admin\model\System as SystemModel;
use app\sports_admin\service\System as SystemService;
use think\Cache;
use think\image\Exception;

//系统类
class System extends Base
{
    protected $beforeActionList = [
        'isAdmin'=>['only'=>'preservation']
    ];
    //系统设置页
    public function index()
    {
        $systemInfo = SystemModel::where('id',1)->find();
        return view('index',compact('systemInfo'));
    }
    /**
     * 保存系统信息
    */
    public function preservation()
    {
        $result = SystemService::preservation();
        if(!Cache::set('systemStatus',$result['is_open'])){
            throw new Exception('服务器缓存异常');
        }
        return json(['code'=>200,'msg'=>'保存成功']);
    }
}